#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include "financial_income_analytics.h"

// 简单测试函数
bool testFinancialIncomeAnalytics() {
    try {
        qDebug() << "开始测试 financial_income_analytics 类...";
        
        // 创建实例
        financial_income_analytics *analytics = new financial_income_analytics();
        qDebug() << "成功创建 financial_income_analytics 实例";
        
        // 测试 calculateChangeRate 函数
        double rate = analytics->calculateChangeRate(100.0, 80.0);
        qDebug() << "calculateChangeRate(100, 80) =" << rate;
        
        // 测试 isValidIncomeData 函数
        bool valid = analytics->isValidIncomeData(1000.0);
        qDebug() << "isValidIncomeData(1000) =" << valid;
        
        // 测试基本的构造和析构
        delete analytics;
        qDebug() << "成功删除实例，内存管理正常";
        
        qDebug() << "测试完成，没有崩溃";
        return true;
    } catch (const std::exception& e) {
        qDebug() << "测试异常:" << e.what();
        return false;
    } catch (...) {
        qDebug() << "测试遇到未知异常";
        return false;
    }
}

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    
    qDebug() << "程序启动，测试 financial_income_analytics 类的稳定性";
    
    bool testResult = testFinancialIncomeAnalytics();
    
    if (testResult) {
        QMessageBox::information(nullptr, "测试结果", "financial_income_analytics 类测试通过，没有崩溃！");
    } else {
        QMessageBox::critical(nullptr, "测试结果", "financial_income_analytics 类测试失败！");
    }
    
    return 0;
}